# Copyright 2010-2014 David "Alemarius Nexus" Lerch
# 
# This file is part of gtatools-test.
#
# gtatools-test is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# gtatools-test is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with gtatools-test.  If not, see <http://www.gnu.org/licenses/>.

# Additional permissions are granted, which are listed in the file
# GPLADDITIONS.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(gtatools-test C CXX)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "gtatools-test - A test program for gtatools")
SET(CPACK_PACKAGE_VENDOR "David 'Alemarius Nexus' Lerch")
#SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "1")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_SOURCE_IGNORE_FILES "\\\\.svn;.*~")

INCLUDE(CPack)
INCLUDE(CheckSymbolExists)

SET(GT_GTASA_PATH "" CACHE PATH "Path to the GTA San Andreas root directory")
SET(GT_WINDOW_WIDTH "512" CACHE STRING "Width in pixels of the GL window")
SET(GT_WINDOW_HEIGHT "512" CACHE STRING "Height in pixels of the GL window")
SET(GT_WINDOW_POS_X "0" CACHE STRING "X position of the GL window")
SET(GT_WINDOW_POS_Y "0" CACHE STRING "X position of the GL window")
SET(GT_WINDOW_FULLSCREEN OFF CACHE BOOL "Whether to use a fullscreen window")
SET(GT_DRAW_DIST_MULTIPLIER "1.0f" CACHE STRING "Draw distances will be multiplied by this factor")


IF(NOT TARGET nxcommon)
    FIND_PACKAGE(Libnxcommon REQUIRED CONFIG)
ENDIF()

INCLUDE(NxResourceCompiler)

IF(NOT TARGET gtaformats)
    FIND_PACKAGE(Libgtaformats REQUIRED CONFIG)
ENDIF()

IF(NOT TARGET gta)
    FIND_PACKAGE(Libgta REQUIRED CONFIG)
ENDIF()

IF(GTAFORMATS_ENABLE_SQUISH)
    FIND_PACKAGE(Libsquish REQUIRED)
ENDIF()

IF(GTAFORMATS_ENABLE_PVRTEXLIB)
    FIND_PACKAGE(PVRTexLib REQUIRED)
ENDIF()

FIND_PACKAGE(CEGUI REQUIRED)

FIND_PACKAGE(Bullet REQUIRED COMPONENTS BulletCollision BulletDynamics LinearMath)
FIND_PACKAGE(SDL REQUIRED)

IF(GTA_USE_OPENGL_ES)
    FIND_LIBRARY(GLESV2_LIBRARIES NAMES GLESv2 libGLESv2)
    FIND_LIBRARY(EGL_LIBRARIES NAMES EGL libEGL)
    FIND_PATH(GLESV2_INCLUDE_DIRS GLES2/gl2.h)
    FIND_PATH(EGL_INCLUDE_DIRS EGL/egl.h)
ELSE(GTA_USE_OPENGL_ES)
    FIND_PACKAGE(OpenGL)
    FIND_LIBRARY(GLEW_LIBRARIES NAMES GLEW libGLEW glew glew32 libglew libglew32)
    FIND_PATH(GLEW_INCLUDE_DIRS GL/glew.h)
ENDIF(GTA_USE_OPENGL_ES)

SET(LIBRARIES gta gtaformats nxcommon)
SET(INCLUDES "")

IF(GTAFORMATS_ENABLE_SQUISH)
    SET(LIBRARIES ${LIBRARIES} "${LIBSQUISH_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${LIBSQUISH_INCLUDE_DIRS}")
ENDIF()

IF(GTAFORMATS_ENABLE_PVRTEXLIB)
    SET(LIBRARIES ${LIBRARIES} "${PVRTEXLIB_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${PVRTEXLIB_INCLUDE_DIRS}")
ENDIF()

IF(GTA_USE_OPENGL_ES)
    SET(LIBRARIES ${LIBRARIES} "${GLESV2_LIBRARIES}" "${EGL_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${GLESV2_INCLUDE_DIRS}" "${EGL_INCLUDE_DIRS}")
ELSE(GTA_USE_OPENGL_ES)
    SET(LIBRARIES ${LIBRARIES} "${OPENGL_gl_LIBRARY}" "${GLEW_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${OPENGL_INCLUDE_DIR}" "${GLEW_INCLUDE_DIRS}")
ENDIF(GTA_USE_OPENGL_ES)

SET(LIBRARIES ${LIBRARIES} ${CEGUI_LIBRARIES})
SET(INCLUDES ${INCLUDES} ${CEGUI_INCLUDE_DIRS})

SET(LIBRARIES ${LIBRARIES} ${BULLET_LIBRARIES})
SET(INCLUDES ${INCLUDES} ${BULLET_INCLUDE_DIRS})

SET(LIBRARIES ${LIBRARIES} ${SDL_LIBRARY})
SET(INCLUDES ${INCLUDES} ${SDL_INCLUDE_DIR})

SET(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/config")

SET(ADDITIONAL_INSTALL_FILES "" CACHE STRING "Paths to files which will be additionally installed to the bin subdirectory.")
SET(ADDITIONAL_INSTALL_FILES_ENABLED OFF CACHE BOOL "Set true to enable ADDITIONAL_INSTALL_FILES")

SET(SRCS main Controller VehicleController SphericalCameraController BulletGLDebugDraw)

FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/config/gtatools-test")
CONFIGURE_FILE(config.cmake.h "${CMAKE_BINARY_DIR}/config/gtatools-test/config.h")

CREATE_RESOURCE(shaders/btgldebugdraw_vertex.glsl btgldebugdraw_vertex_shader)
CREATE_RESOURCE(shaders/btgldebugdraw_fragment.glsl btgldebugdraw_fragment_shader)

INCLUDE_DIRECTORIES(${INCLUDES})

ADD_EXECUTABLE (
    gtatools-test
    ${SRCS} ${MOC_COMPILED_SRCS} ${UIC_COMPILED_SRCS}
)

TARGET_LINK_LIBRARIES(gtatools-test ${LIBRARIES})

INSTALL(TARGETS gtatools-test DESTINATION bin)

IF(ADDITIONAL_INSTALL_FILES_ENABLED AND ADDITIONAL_INSTALL_FILES)
    INSTALL(FILES ${ADDITIONAL_INSTALL_FILES} DESTINATION bin)
ENDIF(ADDITIONAL_INSTALL_FILES_ENABLED AND ADDITIONAL_INSTALL_FILES)
